package com.miracle.flexAPI.api.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.miracle.flexAPI.api.entity.SysTask;
import com.miracle.flexAPI.api.service.TaskManageService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

/**
 * 任务管理
 *
 * @author miracle
 * @since 2021-08-23 16:05:08
 */
@RestController
@RequestMapping("TaskManage")
@Api(value = "TaskManage", tags = {"任务管理"})
public class TaskManageController {

    @Resource
    private TaskManageService taskManageService;

    @GetMapping(value = "list")
    @ApiOperation(value = "任务管理-列表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "searchValue", value = "关键字", paramType = "query"),
        @ApiImplicitParam(name = "taskPurpose", value = "用途", paramType = "query"),
        @ApiImplicitParam(name = "taskSource", value = "数据源", paramType = "query"),
        @ApiImplicitParam(name = "status", value = "状态", paramType = "query"),
        @ApiImplicitParam(name = "params[create]", value = "参数1", paramType = "query"),
        @ApiImplicitParam(name = "params[update]", value = "参数2", paramType = "query"),
    })
    @ApiResponses({
        @ApiResponse(code = 200, message =
            "taskId : 任务ID\n" +
            "taskName : 任务名称\n" +
            "taskType : 任务类型(1:SQL，)\n" +
            "taskPurpose : 用途（1.菜单...）\n" +
            "taskSourceId : 数据源ID\n" +
            "taskSql : 查询sql\n" +
            "status : 状态(0:无效，1:有效)\n" +
            "remark : 备注\n" +
            "cacheConfigId : 缓存策略ID\n" +
            "createBy : 创建人\n" +
            "createTime : 创建时间\n" +
            "updateBy : 更新人\n" +
            "updateTime : 更新时间\n"
        )
    })
    public AjaxResult list(@ApiIgnore SysTask model) {
        return taskManageService.list(model);
    }


    @PostMapping (value = "add")
    @ApiOperation(value = "任务管理-添加")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "taskId", value = "任务ID", paramType = "query"),
        @ApiImplicitParam(name = "taskName", value = "任务名称", paramType = "query"),
        @ApiImplicitParam(name = "taskType", value = "任务类型(1:SQL，)", paramType = "query"),
        @ApiImplicitParam(name = "taskPurpose", value = "用途（1.菜单...）", paramType = "query"),
        @ApiImplicitParam(name = "taskSourceId", value = "数据源ID", paramType = "query"),
        @ApiImplicitParam(name = "taskSql", value = "查询sql", paramType = "query"),
        @ApiImplicitParam(name = "status", value = "状态(0:无效，1:有效)", paramType = "query"),
        @ApiImplicitParam(name = "remark", value = "备注", paramType = "query"),
        @ApiImplicitParam(name = "cacheConfigId", value = "缓存策略ID", paramType = "query"),
    })
    public AjaxResult add(@ApiIgnore SysTask dto) throws Exception {
        return taskManageService.add(dto);
    }


    @PutMapping(value = "edit")
    @ApiOperation(value = "任务管理-编辑")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "taskId", value = "任务ID", paramType = "query"),
        @ApiImplicitParam(name = "taskName", value = "任务名称", paramType = "query"),
        @ApiImplicitParam(name = "taskType", value = "任务类型(1:SQL，)", paramType = "query"),
        @ApiImplicitParam(name = "taskPurpose", value = "用途（1.菜单...）", paramType = "query"),
        @ApiImplicitParam(name = "taskSourceId", value = "数据源ID", paramType = "query"),
        @ApiImplicitParam(name = "taskSql", value = "查询sql", paramType = "query"),
        @ApiImplicitParam(name = "status", value = "状态(0:无效，1:有效)", paramType = "query"),
        @ApiImplicitParam(name = "remark", value = "备注", paramType = "query"),
        @ApiImplicitParam(name = "cacheConfigId", value = "缓存策略ID", paramType = "query"),
    })
    public AjaxResult edit(@ApiIgnore SysTask dto) throws Exception {
        return taskManageService.edit(dto);
    }


    @DeleteMapping(value = "delete")
    @ApiOperation(value = "任务管理-删除")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "taskId", value = "任务ID", paramType = "query"),
    })
    public AjaxResult delete(@ApiIgnore SysTask dto) {
        return taskManageService.delete(dto);
    }


    @PostMapping(value = "execute")
    @ApiOperation(value = "任务管理-执行")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "taskId", value = "任务ID", paramType = "query"),
        @ApiImplicitParam(name = "params[P1]", value = "参数一", paramType = "query"),
        @ApiImplicitParam(name = "params[P2]", value = "参数二", paramType = "query"),
        @ApiImplicitParam(name = "params[P3]", value = "参数三", paramType = "query"),
        @ApiImplicitParam(name = "params[P4]", value = "参数四", paramType = "query"),
        @ApiImplicitParam(name = "params[P5]", value = "参数五", paramType = "query"),
        @ApiImplicitParam(name = "params[P9]", value = "参数九", paramType = "query"),
        @ApiImplicitParam(name = "params[PU]", value = "参数user", paramType = "query"),
    })
    public AjaxResult execute(@ApiIgnore SysTask dto) {
        AjaxResult result = taskManageService.executeTaskById4Page(dto);
        return result;
    }

}
